﻿using System;
using System.Collections.Generic;
using System.Linq;
using Assist;
using Autodesk.Revit.DB;
using YJKGeometryFuncs;
using YJKCopyModel.Forms;

namespace YJKCopyModel.CommonTrans
{
	public class DoubleCurveManager
	{
		public static List<DoubleParaleCurve> GetDuctCurves(List<Curve> lstCurve, double dMaxWidth, double dMinWidth, double dMinLen)
		{
			Dictionary<XYZ, List<Line>> parallelLines = new Dictionary<XYZ, List<Line>>(new ExtendXYZComparer(4));
			Dictionary<XYZ, List<Arc>> parallelArcs = new Dictionary<XYZ, List<Arc>>(new ExtendXYZComparer(4));
			DoubleCurveManager.GetCurveGroups(lstCurve, parallelLines, parallelArcs);
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			list.AddRange(DoubleCurveManager.GetDuctLines(parallelLines, dMaxWidth, dMinWidth, dMinLen));
			list.AddRange(DoubleCurveManager.GetDuctArcs(parallelArcs, dMaxWidth, dMinWidth, dMinLen));
			DoubleCurveManager.ClearShortEndLine(list);
			return list;
		}

		private static List<DoubleParaleCurve> GetDuctLines(Dictionary<XYZ, List<Line>> parallelLines, double dMaxWidth, double dMinWidth, double dMinLength)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			foreach (KeyValuePair<XYZ, List<Line>> keyValuePair in parallelLines)
			{
				XYZ xyz = XYZ.Zero + Geometry.RotateTo(keyValuePair.Key, Math.PI*.5, XYZ.BasisZ) * 1000000.0;
				List<KeyValuePair<XYZ, Line>> list2 = new List<KeyValuePair<XYZ, Line>>();
				foreach (Line line in keyValuePair.Value)
				{
					XYZ key = Geometry.CalculateFootPoint(XYZ.Zero, xyz, line.GetEndPoint(0));
					KeyValuePair<XYZ, Line> item = new KeyValuePair<XYZ, Line>(key, line);
					list2.Add(item);
				}
				list2.Sort(new ParallelLineComparer(xyz));
				Dictionary<XYZ, List<Line>> dictionary = new Dictionary<XYZ, List<Line>>(new ExtendXYZComparer(4));
				foreach (KeyValuePair<XYZ, Line> keyValuePair2 in list2)
				{
					bool flag = dictionary.ContainsKey(keyValuePair2.Key);
					if (flag)
					{
						dictionary[keyValuePair2.Key].Add(keyValuePair2.Value);
					}
					else
					{
						List<Line> list3 = new List<Line>();
						list3.Add(keyValuePair2.Value);
						dictionary.Add(keyValuePair2.Key, list3);
					}
				}
				for (int i = 0; i < dictionary.Count; i++)
				{
					DoubleCurveManager.MergeOverlapLines(dictionary.ElementAt(i).Value);
				}
				for (int j = 0; j < dictionary.Count - 1; j++)
				{
					KeyValuePair<XYZ, List<Line>> keyValuePair3 = dictionary.ElementAt(j);
					List<Line> value = keyValuePair3.Value;
					for (int k = j + 1; k < dictionary.Count; k++)
					{
						KeyValuePair<XYZ, List<Line>> keyValuePair4 = dictionary.ElementAt(k);
						double val = keyValuePair3.Key.DistanceTo(keyValuePair4.Key);
						bool flag2 = Geometry.LessThan(val, dMinWidth, DoubleCurveManager.m_dTolerance);
						if (!flag2)
						{
							bool flag3 = Geometry.GreaterThan(val, dMaxWidth, DoubleCurveManager.m_dTolerance);
							if (flag3)
							{
								break;
							}
							List<Line> value2 = keyValuePair4.Value;
							list.AddRange(DoubleCurveManager.GetParalelLines(value, value2, 0.45, dMaxWidth, dMinWidth, dMinLength, false));
							bool flag4 = value.Count < 1;
							if (flag4)
							{
								break;
							}
						}
					}
				}
			}
			return list;
		}

		private static List<DoubleParaleCurve> GetDuctArcs(Dictionary<XYZ, List<Arc>> parallelArcs, double dMaxWidth, double dMinWidth, double dMinLength)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			foreach (KeyValuePair<XYZ, List<Arc>> keyValuePair in parallelArcs)
			{
				List<Arc> value = keyValuePair.Value;
				value.Sort((Arc a1, Arc a2) => a1.Radius.CompareTo(a2.Radius));
				Dictionary<int, List<Arc>> dictionary = new Dictionary<int, List<Arc>>();
				foreach (Arc arc in value)
				{
					int key = Convert.ToInt32(AssistFunc.feetToMM(arc.Radius));
					bool flag = dictionary.ContainsKey(key);
					if (flag)
					{
						dictionary[key].Add(arc);
					}
					else
					{
						dictionary.Add(key, new List<Arc>
						{
							arc
						});
					}
				}
				for (int i = 0; i < dictionary.Count; i++)
				{
					DoubleCurveManager.MergeOverlapArcs(dictionary.ElementAt(i).Value);
				}
				for (int j = 0; j < dictionary.Count - 1; j++)
				{
					KeyValuePair<int, List<Arc>> keyValuePair2 = dictionary.ElementAt(j);
					List<Arc> value2 = keyValuePair2.Value;
					for (int k = j + 1; k < dictionary.Count; k++)
					{
						KeyValuePair<int, List<Arc>> keyValuePair3 = dictionary.ElementAt(k);
						double val = AssistFunc.mmToFeet((double)Math.Abs(keyValuePair2.Key - keyValuePair3.Key));
						bool flag2 = Geometry.GreaterThan(val, dMaxWidth);
						if (flag2)
						{
							break;
						}
						List<Arc> value3 = keyValuePair3.Value;
						list.AddRange(DoubleCurveManager.GetParalelArcs(value2, value3, 0.48, dMaxWidth, dMinWidth, dMinLength));
						bool flag3 = value2.Count < 1;
						if (flag3)
						{
							break;
						}
					}
				}
			}
			return list;
		}

		public static List<DoubleParaleCurve> GetWallCurves(List<Curve> lstCurve, List<Curve> lstWindowBase, QuickModelProgressBar progress, double dMaxWidth, double dMinWidth, double dMinLen)
		{
			DoubleCurveManager.m_lstAllCurve.Clear();
			DoubleCurveManager.m_lstAllCurve.AddRange(lstCurve);
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			progress.RefreshProgressBar("正在识别墙...");
			List<Line> lstBreakLine = DoubleCurveManager.FindWallBreakLine(lstCurve, dMaxWidth, dMinWidth);
			bool isDisposed = progress.IsDisposed;
			List<DoubleParaleCurve> result;
			if (isDisposed)
			{
				result = list;
			}
			else
			{
				progress.RefreshProgressBar("正在识别墙...");
				Dictionary<XYZ, List<Line>> parallelLines = new Dictionary<XYZ, List<Line>>(new ExtendXYZComparer(4));
				Dictionary<XYZ, List<Arc>> parallelArcs = new Dictionary<XYZ, List<Arc>>(new ExtendXYZComparer(4));
				DoubleCurveManager.GetCurveGroups(lstCurve, parallelLines, parallelArcs);
				bool isDisposed2 = progress.IsDisposed;
				if (isDisposed2)
				{
					result = list;
				}
				else
				{
					progress.RefreshProgressBar("正在识别墙...");
					list.AddRange(DoubleCurveManager.GetWallLines(parallelLines, dMaxWidth, dMinWidth, dMinLen));
					list.AddRange(DoubleCurveManager.GetWallArcs(parallelArcs, dMaxWidth, dMinWidth, dMinLen));
					bool isDisposed3 = progress.IsDisposed;
					if (isDisposed3)
					{
						result = list;
					}
					else
					{
						progress.RefreshProgressBar("正在识别墙...");
						DoubleCurveManager.ClearShortEndLine(list);
						bool isDisposed4 = progress.IsDisposed;
						if (isDisposed4)
						{
							result = list;
						}
						else
						{
							progress.RefreshProgressBar("正在识别墙...");
							DoubleCurveManager.MergeWindowCurves(lstWindowBase, list);
							bool isDisposed5 = progress.IsDisposed;
							if (isDisposed5)
							{
								result = list;
							}
							else
							{
								progress.RefreshProgressBar("正在识别墙...");
								DoubleCurveManager.MergeParalelCurves(list);
								bool isDisposed6 = progress.IsDisposed;
								if (isDisposed6)
								{
									result = list;
								}
								else
								{
									progress.RefreshProgressBar("正在识别墙...");
									DoubleCurveManager.BreakParalelCurves(lstBreakLine, list);
									bool flag = !progress.IsDisposed;
									if (flag)
									{
										progress.RefreshProgressBar("正在识别墙...");
									}
									result = list;
								}
							}
						}
					}
				}
			}
			return result;
		}

		private static List<DoubleParaleCurve> GetWallLines(Dictionary<XYZ, List<Line>> parallelLines, double dMaxWidth, double dMinWidth, double dMinLength)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			foreach (KeyValuePair<XYZ, List<Line>> keyValuePair in parallelLines)
			{
				XYZ xyz = XYZ.Zero + Geometry.RotateTo(keyValuePair.Key, Math.PI*.5, XYZ.BasisZ) * 1000000.0;
				List<KeyValuePair<XYZ, Line>> list2 = new List<KeyValuePair<XYZ, Line>>();
				foreach (Line line in keyValuePair.Value)
				{
					XYZ key = Geometry.CalculateFootPoint(XYZ.Zero, xyz, line.GetEndPoint(0));
					KeyValuePair<XYZ, Line> item = new KeyValuePair<XYZ, Line>(key, line);
					list2.Add(item);
				}
				list2.Sort(new ParallelLineComparer(xyz));
				Dictionary<XYZ, List<Line>> dictionary = new Dictionary<XYZ, List<Line>>(new ExtendXYZComparer(4));
				foreach (KeyValuePair<XYZ, Line> keyValuePair2 in list2)
				{
					bool flag = dictionary.ContainsKey(keyValuePair2.Key);
					if (flag)
					{
						dictionary[keyValuePair2.Key].Add(keyValuePair2.Value);
					}
					else
					{
						List<Line> list3 = new List<Line>();
						list3.Add(keyValuePair2.Value);
						dictionary.Add(keyValuePair2.Key, list3);
					}
				}
				for (int i = 0; i < dictionary.Count; i++)
				{
					DoubleCurveManager.MergeOverlapLines(dictionary.ElementAt(i).Value);
				}
				for (int j = 0; j < dictionary.Count - 1; j++)
				{
					KeyValuePair<XYZ, List<Line>> keyValuePair3 = dictionary.ElementAt(j);
					List<Line> value = keyValuePair3.Value;
					bool flag2 = value.Count < 1;
					if (!flag2)
					{
						for (int k = j + 1; k < dictionary.Count; k++)
						{
							KeyValuePair<XYZ, List<Line>> keyValuePair4 = dictionary.ElementAt(k);
							double num = keyValuePair3.Key.DistanceTo(keyValuePair4.Key);
							bool flag3 = DoubleCurveManager.GetConstWallWidth(num) < 0.0;
							if (!flag3)
							{
								bool flag4 = Geometry.LessThan(num, dMinWidth, DoubleCurveManager.m_dTolerance);
								if (!flag4)
								{
									bool flag5 = Geometry.GreaterThan(num, dMaxWidth, DoubleCurveManager.m_dTolerance);
									if (flag5)
									{
										break;
									}
									List<Line> value2 = keyValuePair4.Value;
									DoubleCurveManager.MergeGroupLines(value, value2);
									DoubleCurveManager.MergeGroupLines(value2, value);
									list.AddRange(DoubleCurveManager.GetParalelLines(value, value2, 0.28, dMaxWidth, dMinWidth, dMinLength, true));
									bool flag6 = value.Count < 1;
									if (flag6)
									{
										break;
									}
								}
							}
						}
					}
				}
			}
			return list;
		}

		private static List<DoubleParaleCurve> GetWallArcs(Dictionary<XYZ, List<Arc>> parallelArcs, double dMaxWidth, double dMinWidth, double dMinLength)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			foreach (KeyValuePair<XYZ, List<Arc>> keyValuePair in parallelArcs)
			{
				List<Arc> value = keyValuePair.Value;
				value.Sort((Arc a1, Arc a2) => a1.Radius.CompareTo(a2.Radius));
				Dictionary<int, List<Arc>> dictionary = new Dictionary<int, List<Arc>>();
				foreach (Arc arc in value)
				{
					int key = Convert.ToInt32(AssistFunc.feetToMM(arc.Radius));
					bool flag = dictionary.ContainsKey(key);
					if (flag)
					{
						dictionary[key].Add(arc);
					}
					else
					{
						dictionary.Add(key, new List<Arc>
						{
							arc
						});
					}
				}
				for (int i = 0; i < dictionary.Count; i++)
				{
					DoubleCurveManager.MergeOverlapArcs(dictionary.ElementAt(i).Value);
				}
				for (int j = 0; j < dictionary.Count - 1; j++)
				{
					KeyValuePair<int, List<Arc>> keyValuePair2 = dictionary.ElementAt(j);
					List<Arc> value2 = keyValuePair2.Value;
					for (int k = j + 1; k < dictionary.Count; k++)
					{
						KeyValuePair<int, List<Arc>> keyValuePair3 = dictionary.ElementAt(k);
						double val = AssistFunc.mmToFeet((double)Math.Abs(keyValuePair2.Key - keyValuePair3.Key));
						bool flag2 = Geometry.GreaterThan(val, dMaxWidth);
						if (flag2)
						{
							break;
						}
						List<Arc> value3 = keyValuePair3.Value;
						DoubleCurveManager.MergeGroupArcs(value2, value3);
						DoubleCurveManager.MergeGroupArcs(value3, value2);
						list.AddRange(DoubleCurveManager.GetParalelArcs(value2, value3, 0.28, dMaxWidth, dMinWidth, dMinLength));
						bool flag3 = value2.Count < 1;
						if (flag3)
						{
							break;
						}
					}
				}
			}
			return list;
		}

		private static void MergeWindowCurves(List<Curve> lstWindowBaseLine, List<DoubleParaleCurve> lstWallBorderCurve)
		{
			bool flag = lstWindowBaseLine == null;
			if (!flag)
			{
				double dVerticalOffset = AssistFunc.mmToFeet(10.0);
				double dWidthExtend = AssistFunc.mmToFeet(10.0);
				for (int i = 0; i < lstWindowBaseLine.Count; i++)
				{
					Line line = lstWindowBaseLine[i] as Line;
					bool flag2 = line == null;
					if (!flag2)
					{
						bool flag3 = DoubleCurveManager.MergeWindowLine(line, dWidthExtend, dVerticalOffset, lstWallBorderCurve);
						if (flag3)
						{
							lstWindowBaseLine.RemoveAt(i);
							i--;
						}
					}
				}
			}
		}

		private static bool MergeWindowLine(Line windowLine, double dWidthExtend, double dVerticalOffset, List<DoubleParaleCurve> lstWallBorderCurve)
		{
			XYZ direction = windowLine.Direction;
			XYZ xyz = windowLine.GetEndPoint(0);
			XYZ xyz2 = windowLine.GetEndPoint(1);
			xyz -= direction * dWidthExtend;
			xyz2 += direction * dWidthExtend;
			for (int i = 0; i < lstWallBorderCurve.Count; i++)
			{
				DoubleParaleCurve doubleParaleCurve = lstWallBorderCurve[i];
				Line line = doubleParaleCurve.LocationCurve as Line;
				bool flag = line == null;
				if (!flag)
				{
					bool flag2 = !DoubleCurveManager.IsVectorParalel(direction, line.Direction);
					if (!flag2)
					{
						XYZ endPoint = line.GetEndPoint(0);
						XYZ endPoint2 = line.GetEndPoint(1);
						XYZ xyz3 = Geometry.CalculateFootPoint(endPoint, endPoint2, xyz);
						XYZ xyz4 = Geometry.CalculateFootPoint(endPoint, endPoint2, xyz2);
						double val = xyz3.DistanceTo(xyz);
						bool flag3 = Geometry.GreaterThan(val, dVerticalOffset);
						if (!flag3)
						{
							bool flag4 = Geometry.Is_Point_OnSegment(endPoint, endPoint2, xyz3, DoubleCurveManager.m_dTolerance);
							bool result;
							if (flag4)
							{
								DoubleCurveManager.ExtendParalelLine(xyz4, ref doubleParaleCurve);
								result = true;
							}
							else
							{
								bool flag5 = Geometry.Is_Point_OnSegment(endPoint, endPoint2, xyz4, DoubleCurveManager.m_dTolerance);
								if (!flag5)
								{
									goto IL_117;
								}
								DoubleCurveManager.ExtendParalelLine(xyz3, ref doubleParaleCurve);
								result = true;
							}
							return result;
						}
					}
				}
				IL_117:;
			}
			return false;
		}

		private static void MergeParalelCurves(List<DoubleParaleCurve> lstParalelCurve)
		{
			double dMinOffset = AssistFunc.mmToFeet(5.0);
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			for (int i = 0; i < lstParalelCurve.Count; i++)
			{
				DoubleParaleCurve doubleParaleCurve = lstParalelCurve[i];
				bool flag = doubleParaleCurve.LocationCurve is Line;
				if (flag)
				{
					list.Add(doubleParaleCurve);
					lstParalelCurve.RemoveAt(i);
					i--;
				}
			}
			List<List<DoubleParaleCurve>> list2 = new List<List<DoubleParaleCurve>>();
			while (list.Count > 0)
			{
				List<DoubleParaleCurve> list3 = new List<DoubleParaleCurve>();
				DoubleParaleCurve doubleParaleCurve2 = list[0];
				list3.Add(doubleParaleCurve2);
				list.RemoveAt(0);
				for (int j = 0; j < list.Count; j++)
				{
					DoubleParaleCurve doubleParaleCurve3 = list[j];
					bool flag2 = DoubleCurveManager.TwoParalelLineOnOneLine(doubleParaleCurve2, doubleParaleCurve3, dMinOffset);
					if (flag2)
					{
						list3.Add(doubleParaleCurve3);
						list.RemoveAt(j);
						j--;
					}
				}
				list2.Add(list3);
			}
			DoubleCurveManager.MergeParalelLinesOnOneLines(list2, dMinOffset);
			foreach (List<DoubleParaleCurve> collection in list2)
			{
				lstParalelCurve.AddRange(collection);
			}
		}

		private static void MergeParalelLinesOnOneLines(List<List<DoubleParaleCurve>> lstParalelLinesOnOneLines, double dMinOffset)
		{
			foreach (List<DoubleParaleCurve> list in lstParalelLinesOnOneLines)
			{
				DoubleCurveManager.SortParalelLinesOnOneLine(list);
				for (int i = 0; i < list.Count - 1; i++)
				{
					DoubleParaleCurve doubleParaleCurve = list[i];
					for (int j = i + 1; j < list.Count; j++)
					{
						DoubleParaleCurve wallCurve = list[j];
						bool flag = DoubleCurveManager.MergeParalelLine(wallCurve, dMinOffset, ref doubleParaleCurve);
						if (!flag)
						{
							break;
						}
						list.RemoveAt(j);
						j--;
					}
				}
			}
		}

		private static bool MergeParalelLine(DoubleParaleCurve wallCurve1, double dMinOffset, ref DoubleParaleCurve wallCurve2)
		{
			Line line = wallCurve1.LocationCurve as Line;
			Line line2 = wallCurve2.LocationCurve as Line;
			bool flag = line == null || line2 == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				double val = Math.Abs(wallCurve1.Width - wallCurve2.Width);
				bool flag2 = Geometry.GreaterThan(val, 0.001);
				if (flag2)
				{
					result = false;
				}
				else
				{
					XYZ direction = line.Direction;
					XYZ direction2 = line2.Direction;
					bool flag3 = !DoubleCurveManager.IsVectorEqual(direction, direction2);
					if (flag3)
					{
						result = false;
					}
					else
					{
						XYZ endPoint = line.GetEndPoint(0);
						XYZ endPoint2 = line.GetEndPoint(1);
						XYZ endPoint3 = line2.GetEndPoint(0);
						XYZ endPoint4 = line2.GetEndPoint(1);
						XYZ xyz = Geometry.CalculateFootPoint(endPoint3, endPoint4, endPoint);
						XYZ xyz2 = Geometry.CalculateFootPoint(endPoint3, endPoint4, endPoint2);
						double val2 = xyz.DistanceTo(endPoint);
						bool flag4 = Geometry.GreaterThan(val2, dMinOffset);
						if (flag4)
						{
							result = false;
						}
						else
						{
							bool flag5 = Geometry.Is_Point_OnSegment(endPoint3, endPoint4, xyz, DoubleCurveManager.m_dTolerance);
							if (flag5)
							{
								DoubleCurveManager.ExtendParalelLine(xyz2, ref wallCurve2);
								result = true;
							}
							else
							{
								bool flag6 = Geometry.Is_Point_OnSegment(endPoint3, endPoint4, xyz2, DoubleCurveManager.m_dTolerance);
								if (flag6)
								{
									DoubleCurveManager.ExtendParalelLine(xyz, ref wallCurve2);
									result = true;
								}
								else
								{
									result = false;
								}
							}
						}
					}
				}
			}
			return result;
		}

		private static void ExtendParalelLine(XYZ ptExtend, ref DoubleParaleCurve wallCurve)
		{
			XYZ endPoint = wallCurve.LocationCurve.GetEndPoint(0);
			XYZ endPoint2 = wallCurve.LocationCurve.GetEndPoint(1);
			DoubleCurveManager.ExtendLine(ptExtend, ref endPoint, ref endPoint2);
			wallCurve.LocationCurve = Line.CreateBound(endPoint, endPoint2);
			Line line = wallCurve.FirstParalelCurve as Line;
			XYZ endPoint3 = line.GetEndPoint(0);
			XYZ endPoint4 = line.GetEndPoint(1);
			XYZ ptExtend2 = Geometry.CalculateFootPoint(endPoint3, endPoint4, ptExtend);
			DoubleCurveManager.ExtendLine(ptExtend2, ref endPoint3, ref endPoint4);
			wallCurve.FirstParalelCurve = Line.CreateBound(endPoint3, endPoint4);
			Line line2 = wallCurve.SecondParalelCurve as Line;
			XYZ endPoint5 = line2.GetEndPoint(0);
			XYZ endPoint6 = line2.GetEndPoint(1);
			XYZ ptExtend3 = Geometry.CalculateFootPoint(endPoint5, endPoint6, ptExtend);
			DoubleCurveManager.ExtendLine(ptExtend3, ref endPoint5, ref endPoint6);
			wallCurve.SecondParalelCurve = Line.CreateBound(endPoint5, endPoint6);
		}

		private static void SortParalelLinesOnOneLine(List<DoubleParaleCurve> lstParalelLinesOneLine)
		{
			bool flag = lstParalelLinesOneLine == null || lstParalelLinesOneLine.Count < 1;
			if (!flag)
			{
				Line line = lstParalelLinesOneLine[0].LocationCurve as Line;
				XYZ direction = line.Direction;
				for (int i = 0; i < lstParalelLinesOneLine.Count - 1; i++)
				{
					DoubleParaleCurve doubleParaleCurve = lstParalelLinesOneLine[i];
					XYZ xyz = doubleParaleCurve.LocationCurve.Evaluate(0.5, true);
					for (int j = i + 1; j < lstParalelLinesOneLine.Count; j++)
					{
						DoubleParaleCurve doubleParaleCurve2 = lstParalelLinesOneLine[j];
						XYZ xyz2 = doubleParaleCurve2.LocationCurve.Evaluate(0.5, true);
						XYZ xyz3 = (xyz2 - xyz).Normalize();
						double val = xyz3.AngleTo(direction);
						bool flag2 = Geometry.GreaterThan(val, 0.001);
						if (flag2)
						{
							xyz = xyz2;
							DoubleParaleCurve value = lstParalelLinesOneLine[i];
							lstParalelLinesOneLine[i] = lstParalelLinesOneLine[j];
							lstParalelLinesOneLine[j] = value;
						}
					}
				}
			}
		}

		private static bool TwoParalelLineOnOneLine(DoubleParaleCurve ParalelLine1, DoubleParaleCurve ParalelLine2, double dMinOffset)
		{
			Line line = ParalelLine1.LocationCurve as Line;
			Line line2 = ParalelLine2.LocationCurve as Line;
			bool flag = line == null || line2 == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ direction = line.Direction;
				XYZ direction2 = line2.Direction;
				bool flag2 = !DoubleCurveManager.IsVectorParalel(direction, direction2);
				if (flag2)
				{
					result = false;
				}
				else
				{
					XYZ endPoint = line.GetEndPoint(0);
					XYZ endPoint2 = line2.GetEndPoint(0);
					XYZ endPoint3 = line2.GetEndPoint(1);
					XYZ xyz = Geometry.CalculateFootPoint(endPoint2, endPoint3, endPoint);
					double val = xyz.DistanceTo(endPoint);
					result = !Geometry.GreaterThan(val, dMinOffset);
				}
			}
			return result;
		}

		private static int ClearShortEndLine(List<DoubleParaleCurve> lstParallelCurve)
		{
			int num = 0;
			for (int i = 0; i < lstParallelCurve.Count; i++)
			{
				DoubleParaleCurve doubleParaleCurve = lstParallelCurve[i];
				bool flag = doubleParaleCurve.LocationCurve.GetType() != typeof(Line) || Geometry.GreaterThan(doubleParaleCurve.LocationCurve.Length, doubleParaleCurve.Width);
				if (!flag)
				{
					for (int j = 0; j < lstParallelCurve.Count; j++)
					{
						bool flag2 = DoubleCurveManager.IsShortEndLine(doubleParaleCurve, lstParallelCurve[j]);
						if (flag2)
						{
							lstParallelCurve.RemoveAt(i);
							num++;
							i--;
							break;
						}
					}
				}
			}
			for (int k = 0; k < lstParallelCurve.Count; k++)
			{
				DoubleParaleCurve doubleParaleCurve2 = lstParallelCurve[k];
				Line line = doubleParaleCurve2.FirstParalelCurve as Line;
				Line line2 = doubleParaleCurve2.SecondParalelCurve as Line;
				bool flag3 = line == null || line2 == null;
				if (!flag3)
				{
					bool flag4 = false;
					bool flag5 = false;
					for (int l = 0; l < lstParallelCurve.Count; l++)
					{
						DoubleParaleCurve doubleParaleCurve3 = lstParallelCurve[l];
						bool flag6 = doubleParaleCurve3.LocationCurve.GetType() != typeof(Line);
						if (!flag6)
						{
							bool flag7 = !flag4;
							if (flag7)
							{
								flag4 = DoubleCurveManager.IsParallelEndLine(line, doubleParaleCurve3);
							}
							bool flag8 = !flag5;
							if (flag8)
							{
								flag5 = DoubleCurveManager.IsParallelEndLine(line2, doubleParaleCurve3);
							}
							bool flag9 = flag4 && flag5;
							if (flag9)
							{
								lstParallelCurve.RemoveAt(k);
								num++;
								k--;
								break;
							}
						}
					}
				}
			}
			return num;
		}

		private static bool IsShortEndLine(DoubleParaleCurve wallEndLine, DoubleParaleCurve wallLine)
		{
			Line line = wallEndLine.LocationCurve as Line;
			Line line2 = wallLine.LocationCurve as Line;
			bool flag = line == null || line2 == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = !Geometry.IsEqual(line.Length, wallLine.Width, DoubleCurveManager.m_dTolerance);
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = !DoubleCurveManager.IsVectorVertical(line.Direction, line2.Direction);
					if (flag3)
					{
						result = false;
					}
					else
					{
						XYZ pt = line.Evaluate(0.5, true);
						XYZ endPoint = line2.GetEndPoint(0);
						XYZ endPoint2 = line2.GetEndPoint(1);
						result = Geometry.Is_Point_OnSegment(endPoint, endPoint2, pt, 1E-09);
					}
				}
			}
			return result;
		}

		private static bool IsParallelEndLine(Line shortLine, DoubleParaleCurve wallLine)
		{
			Line line = wallLine.LocationCurve as Line;
			bool flag = line == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = Geometry.GreaterThan(shortLine.Length, wallLine.Width, DoubleCurveManager.m_dTolerance);
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = !DoubleCurveManager.IsVectorVertical(shortLine.Direction, line.Direction);
					if (flag3)
					{
						result = false;
					}
					else
					{
						XYZ endPoint = shortLine.GetEndPoint(0);
						XYZ endPoint2 = shortLine.GetEndPoint(1);
						XYZ xyzpoint = line.Project(endPoint).XYZPoint;
						bool flag4 = Geometry.GreaterThan(endPoint.DistanceTo(xyzpoint), 0.5 * wallLine.Width, DoubleCurveManager.m_dTolerance) || Geometry.GreaterThan(endPoint2.DistanceTo(xyzpoint), 0.5 * wallLine.Width, DoubleCurveManager.m_dTolerance);
						if (flag4)
						{
							result = false;
						}
						else
						{
							XYZ endPoint3 = line.GetEndPoint(0);
							XYZ endPoint4 = line.GetEndPoint(1);
							result = (Geometry.IsEqual(endPoint3, xyzpoint, DoubleCurveManager.m_dTolerance) || Geometry.IsEqual(endPoint4, xyzpoint, DoubleCurveManager.m_dTolerance));
						}
					}
				}
			}
			return result;
		}

		private static List<Line> FindWallBreakLine(List<Curve> lstCurve, double dMaxLength, double dMinLength)
		{
			List<Line> list = new List<Line>();
			int i = 0;
			while (i < lstCurve.Count)
			{
				Line line = lstCurve[i] as Line;
				bool flag = line != null;
				if (flag)
				{
					bool flag2 = Geometry.LessThan(line.Length, dMinLength) || Geometry.GreaterThan(line.Length, dMaxLength);
					if (!flag2)
					{
						bool flag3 = DoubleCurveManager.IsWallBreakLine(line, lstCurve);
						if (flag3)
						{
							list.Add(line);
						}
					}
				}
				IL_64:
				i++;
				continue;
				goto IL_64;
			}
			return list;
		}

		private static bool IsWallBreakLine(Line lineItem, List<Curve> lstCurve)
		{
			XYZ endPoint = lineItem.GetEndPoint(0);
			XYZ endPoint2 = lineItem.GetEndPoint(1);
			bool flag = false;
			bool flag2 = false;
			foreach (Curve curve in lstCurve)
			{
				Line line = curve as Line;
				bool flag3 = line == null;
				if (!flag3)
				{
					XYZ endPoint3 = lineItem.GetEndPoint(0);
					XYZ endPoint4 = lineItem.GetEndPoint(1);
					bool flag4 = !DoubleCurveManager.IsVectorVertical(lineItem.Direction, line.Direction);
					if (!flag4)
					{
						bool flag5 = Geometry.LessThan(endPoint.DistanceTo(endPoint3), DoubleCurveManager.m_dTolerance) || Geometry.LessThan(endPoint.DistanceTo(endPoint4), DoubleCurveManager.m_dTolerance);
						if (flag5)
						{
							return false;
						}
						bool flag6 = Geometry.LessThan(endPoint2.DistanceTo(endPoint3), DoubleCurveManager.m_dTolerance) || Geometry.LessThan(endPoint2.DistanceTo(endPoint4), DoubleCurveManager.m_dTolerance);
						if (flag6)
						{
							return false;
						}
						bool flag7 = !flag;
						if (flag7)
						{
							flag = Geometry.Is_Point_OnSegment(endPoint3, endPoint4, endPoint, DoubleCurveManager.m_dTolerance);
						}
						bool flag8 = !flag2;
						if (flag8)
						{
							flag2 = Geometry.Is_Point_OnSegment(endPoint3, endPoint4, endPoint2, DoubleCurveManager.m_dTolerance);
						}
						bool flag9 = flag && flag2;
						if (flag9)
						{
							return true;
						}
					}
				}
			}
			return false;
		}

		private static void BreakParalelCurves(List<Line> lstBreakLine, List<DoubleParaleCurve> lstResult)
		{
			foreach (Line line in lstBreakLine)
			{
				foreach (DoubleParaleCurve doubleParaleCurve in lstResult)
				{
					bool flag = !Geometry.IsEqual(line.Length, doubleParaleCurve.Width, DoubleCurveManager.m_dTolerance);
					if (!flag)
					{
						DoubleParaleCurve item = null;
						DoubleParaleCurve item2 = null;
						bool flag2 = DoubleCurveManager.BreakParalelCurve(line, doubleParaleCurve, ref item, ref item2);
						if (flag2)
						{
							lstResult.Remove(doubleParaleCurve);
							lstResult.Add(item);
							lstResult.Add(item2);
							break;
						}
					}
				}
			}
		}

		private static bool BreakParalelCurve(Line breakLine, DoubleParaleCurve paralelCurve, ref DoubleParaleCurve paralelCurve1, ref DoubleParaleCurve paralelCurve2)
		{
			Line line = paralelCurve.LocationCurve as Line;
			bool flag = line == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ xyz = breakLine.GetEndPoint(0);
				XYZ xyz2 = breakLine.GetEndPoint(1);
				double num = AssistFunc.mmToFeet(1.0);
				XYZ xyz3 = (xyz2 - xyz).Normalize();
				xyz -= num * xyz3;
				xyz2 += num * xyz3;
				Line curve = Line.CreateBound(xyz, xyz2);
				XYZ xyz4 = Geometry.IntersectWithTwoCurves(curve, line, xyz, false, false, null);
				bool flag2 = xyz4 == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					XYZ xyz5 = Geometry.IntersectWithTwoCurves(curve, paralelCurve.FirstParalelCurve, xyz, false, false, null);
					bool flag3 = xyz5 == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						XYZ xyz6 = Geometry.IntersectWithTwoCurves(curve, paralelCurve.SecondParalelCurve, xyz, false, false, null);
						bool flag4 = xyz6 == null;
						if (flag4)
						{
							result = false;
						}
						else
						{
							Curve curve2 = null;
							Curve locationCurve = null;
							bool flag5 = !DoubleCurveManager.BreakCurve(xyz4, line, ref curve2, ref locationCurve);
							if (flag5)
							{
								result = false;
							}
							else
							{
								Curve curve3 = null;
								Curve curve4 = null;
								bool flag6 = !DoubleCurveManager.BreakCurve(xyz5, paralelCurve.FirstParalelCurve, ref curve3, ref curve4);
								if (flag6)
								{
									result = false;
								}
								else
								{
									Curve curve5 = null;
									Curve curve6 = null;
									bool flag7 = !DoubleCurveManager.BreakCurve(xyz6, paralelCurve.SecondParalelCurve, ref curve5, ref curve6);
									if (flag7)
									{
										result = false;
									}
									else
									{
										paralelCurve1 = new DoubleParaleCurve();
										paralelCurve2 = new DoubleParaleCurve();
										paralelCurve1.Width = paralelCurve.Width;
										paralelCurve2.Width = paralelCurve.Width;
										paralelCurve1.LocationCurve = curve2;
										paralelCurve2.LocationCurve = locationCurve;
										XYZ xyz7 = curve2.Evaluate(0.5, true);
										XYZ xyz8 = curve3.Evaluate(0.5, true);
										XYZ xyz9 = curve4.Evaluate(0.5, true);
										bool flag8 = xyz8.DistanceTo(xyz7) < xyz9.DistanceTo(xyz7);
										if (flag8)
										{
											paralelCurve1.FirstParalelCurve = curve3;
											paralelCurve2.FirstParalelCurve = curve4;
										}
										else
										{
											paralelCurve1.FirstParalelCurve = curve4;
											paralelCurve2.FirstParalelCurve = curve3;
										}
										XYZ xyz10 = curve5.Evaluate(0.5, true);
										XYZ xyz11 = curve6.Evaluate(0.5, true);
										bool flag9 = xyz10.DistanceTo(xyz7) < xyz11.DistanceTo(xyz7);
										if (flag9)
										{
											paralelCurve1.SecondParalelCurve = curve5;
											paralelCurve2.SecondParalelCurve = curve6;
										}
										else
										{
											paralelCurve1.SecondParalelCurve = curve6;
											paralelCurve2.SecondParalelCurve = curve5;
										}
										result = true;
									}
								}
							}
						}
					}
				}
			}
			return result;
		}

		private static bool BreakCurve(XYZ ptBreak, Curve curveToBreak, ref Curve newCurve1, ref Curve newCurve2)
		{
			bool flag = !DoubleCurveManager.IsPointOnCurveMiddle(ptBreak, curveToBreak);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ endPoint = curveToBreak.GetEndPoint(0);
				XYZ endPoint2 = curveToBreak.GetEndPoint(1);
				bool flag2 = curveToBreak is Line;
				if (flag2)
				{
					Line line = curveToBreak as Line;
					XYZ xyz = Geometry.CalculateFootPoint(endPoint, endPoint2, ptBreak);
					newCurve1 = Line.CreateBound(endPoint, xyz);
					newCurve2 = Line.CreateBound(xyz, endPoint2);
				}
				else
				{
					bool flag3 = curveToBreak is Arc;
					if (flag3)
					{
						Arc arc = curveToBreak as Arc;
						XYZ xyz2 = Geometry.CalculateFootPoint(endPoint, endPoint2, arc.Center, ptBreak);
						XYZ xyz3 = (endPoint - arc.Center).Normalize();
						XYZ xyz4 = (endPoint2 - arc.Center).Normalize();
						XYZ xyz5 = (xyz2 - arc.Center).Normalize();
						double num = XYZ.BasisX.AngleOnPlaneTo(xyz3, XYZ.BasisZ);
						double num2 = XYZ.BasisX.AngleOnPlaneTo(xyz4, XYZ.BasisZ);
						double num3 = XYZ.BasisX.AngleOnPlaneTo(xyz5, XYZ.BasisZ);
						newCurve1 = Arc.Create(arc.Center, arc.Radius, num, num3, XYZ.BasisX, XYZ.BasisY);
						newCurve2 = Arc.Create(arc.Center, arc.Radius, num3, num2, XYZ.BasisX, XYZ.BasisY);
					}
				}
				result = true;
			}
			return result;
		}

		private static bool IsPointOnCurveMiddle(XYZ ptTest, Curve curveItem)
		{
			double val = AssistFunc.mmToFeet(1.0);
			XYZ endPoint = curveItem.GetEndPoint(0);
			XYZ endPoint2 = curveItem.GetEndPoint(1);
			bool flag = Geometry.LessThan(ptTest.DistanceTo(endPoint), val) || Geometry.LessThan(ptTest.DistanceTo(endPoint2), val);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = curveItem is Line;
				if (flag2)
				{
					result = Geometry.Is_Point_OnSegment(endPoint, endPoint2, ptTest, DoubleCurveManager.m_dTolerance);
				}
				else
				{
					bool flag3 = curveItem is Arc;
					if (flag3)
					{
						Arc arc = curveItem as Arc;
						result = Geometry.Is_Point_OnSegment(endPoint, endPoint2, arc.Center, arc.Normal, ptTest, DoubleCurveManager.m_dTolerance);
					}
					else
					{
						result = false;
					}
				}
			}
			return result;
		}

		private static List<DoubleParaleCurve> GetParalelLines(List<Line> lstFirstLine, List<Line> lstSecondLine, double dOverScale, double dMaxWidth, double dMinWidth, double dMinLength, bool bFindWall)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			for (int i = 0; i < lstFirstLine.Count; i++)
			{
				Line line = lstFirstLine[i];
				for (int j = 0; j < lstSecondLine.Count; j++)
				{
					Line line2 = lstSecondLine[j];
					bool flag = DoubleCurveManager.IsParalelLine(line, line2, dOverScale, dMaxWidth, dMinWidth, bFindWall);
					if (flag)
					{
						double width = 0.0;
						Curve curve = null;
						bool flag2 = DoubleCurveManager.GetParalelLineInfo(bFindWall, line, line2, ref width, ref curve) && Geometry.Greaterthan_Or_Equal(curve.Length, dMinLength);
						if (flag2)
						{
							list.Add(new DoubleParaleCurve
							{
								FirstParalelCurve = line,
								SecondParalelCurve = line2,
								Width = width,
								LocationCurve = curve
							});
						}
						lstFirstLine.RemoveAt(i);
						lstSecondLine.RemoveAt(j);
						i--;
						break;
					}
				}
			}
			return list;
		}

		private static List<DoubleParaleCurve> GetParalelArcs(List<Arc> lstFirstArc, List<Arc> lstSecondArc, double dOverScale, double dMaxWidth, double dMinWidth, double dMinLength)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			for (int i = 0; i < lstFirstArc.Count; i++)
			{
				Arc arc = lstFirstArc[i];
				for (int j = 0; j < lstSecondArc.Count; j++)
				{
					Arc arc2 = lstSecondArc[j];
					bool flag = DoubleCurveManager.IsParalelArc(arc, arc2, dOverScale, dMaxWidth, dMinWidth);
					if (flag)
					{
						double width = 0.0;
						Curve locationCurve = null;
						bool paralelArcInfo = DoubleCurveManager.GetParalelArcInfo(arc, arc2, ref width, ref locationCurve);
						if (paralelArcInfo)
						{
							list.Add(new DoubleParaleCurve
							{
								FirstParalelCurve = arc,
								SecondParalelCurve = arc2,
								Width = width,
								LocationCurve = locationCurve
							});
						}
						lstFirstArc.RemoveAt(i);
						lstSecondArc.RemoveAt(j);
						i--;
						break;
					}
				}
			}
			return list;
		}

		private static bool IsParalelLine(Line parallelLine1, Line parallelLine2, double dOverScale, double dMaxWidth, double dMinWidth, bool bFindWall)
		{
			XYZ endPoint = parallelLine1.GetEndPoint(0);
			XYZ endPoint2 = parallelLine1.GetEndPoint(1);
			XYZ endPoint3 = parallelLine2.GetEndPoint(0);
			XYZ endPoint4 = parallelLine2.GetEndPoint(1);
			XYZ xyz = Geometry.CalculateFootPoint(endPoint, endPoint2, endPoint3);
			XYZ ptE = Geometry.CalculateFootPoint(endPoint, endPoint2, endPoint4);
			double val = xyz.DistanceTo(endPoint3);
			bool flag = Geometry.GreaterThan(val, dMaxWidth, DoubleCurveManager.m_dTolerance) || Geometry.LessThan(val, dMinWidth, DoubleCurveManager.m_dTolerance);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ xyz2 = null;
				XYZ xyz3 = null;
				Geometry.OverlapType overlapType = Geometry.IsOverlapOfTwoLine(xyz, ptE, endPoint, endPoint2, ref xyz2, ref xyz3, true, 1E-09, 1E-09);
				bool flag2 = overlapType == Geometry.OverlapType._OT_None || overlapType == Geometry.OverlapType._OT_Linked;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = xyz2 == null || xyz3 == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						double val2 = xyz2.DistanceTo(xyz3);
						double num = parallelLine1.Length + parallelLine2.Length;
						bool flag4 = Geometry.GreaterThan(val2, num * dOverScale);
						if (flag4)
						{
							result = true;
						}
						else
						{
							bool flag5 = !bFindWall;
							if (flag5)
							{
								result = false;
							}
							else
							{
								bool flag6 = Geometry.LessThan(val2, num * 0.1);
								if (flag6)
								{
									result = false;
								}
								else
								{
									Line line = Line.CreateBound(endPoint, endPoint2);
									Line line2 = Line.CreateBound(endPoint3, endPoint4);
									bool flag7 = DoubleCurveManager.IsVectorReverse(line.Direction, line2.Direction);
									if (flag7)
									{
										line2 = Line.CreateBound(endPoint4, endPoint3);
									}
									bool flag8 = DoubleCurveManager.LinkOtherParalelLine(line, line2, 0, dOverScale, dMaxWidth, dMinWidth) || DoubleCurveManager.LinkOtherParalelLine(line, line2, 1, dOverScale, dMaxWidth, dMinWidth);
									result = flag8;
								}
							}
						}
					}
				}
			}
			return result;
		}

		private static bool IsParalelArc(Arc parallelArc1, Arc parallelArc2, double dOverScale, double dMaxWidth, double dMinWidth)
		{
			double val = Math.Abs(parallelArc1.Radius - parallelArc2.Radius);
			bool flag = Geometry.GreaterThan(val, dMaxWidth) || Geometry.LessThan(val, dMinWidth);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ endPoint = parallelArc1.GetEndPoint(0);
				XYZ endPoint2 = parallelArc1.GetEndPoint(1);
				XYZ endPoint3 = parallelArc2.GetEndPoint(0);
				XYZ endPoint4 = parallelArc2.GetEndPoint(1);
				XYZ center = parallelArc1.Center;
				XYZ center2 = parallelArc2.Center;
				XYZ xyz = null;
				XYZ xyz2 = null;
				XYZ ptS = center + (endPoint3 - center).Normalize() * parallelArc1.Radius;
				XYZ ptE = center + (endPoint4 - center).Normalize() * parallelArc1.Radius;
				Geometry.OverlapType overlapType = Geometry.IsOverlapOfTwoArc(endPoint, endPoint2, center, XYZ.BasisZ, ptS, ptE, center, XYZ.BasisZ, ref xyz, ref xyz2, 1E-09);
				bool flag2 = overlapType == Geometry.OverlapType._OT_None || overlapType == Geometry.OverlapType._OT_Linked;
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = xyz == null || xyz2 == null;
					if (flag3)
					{
						result = false;
					}
					else
					{
						double angle = Geometry.getAngle(center, xyz);
						double angle2 = Geometry.getAngle(center, xyz2);
						double val2 = Geometry.BetweenTheAngles(angle, angle2, true);
						angle = Geometry.getAngle(center, endPoint);
						angle2 = Geometry.getAngle(center, endPoint2);
						double num = Geometry.BetweenTheAngles(angle, angle2, true);
						angle = Geometry.getAngle(center2, endPoint3);
						angle2 = Geometry.getAngle(center2, endPoint4);
						double num2 = Geometry.BetweenTheAngles(angle, angle2, true);
						result = Geometry.GreaterThan(val2, (num + num2) * dOverScale);
					}
				}
			}
			return result;
		}

		private static bool LinkOtherParalelLine(Line parallelLine1, Line parallelLine2, int nPointIndex, double dOverScale, double dMaxWidth, double dMinWidth)
		{
			XYZ endPoint = parallelLine1.GetEndPoint(nPointIndex);
			XYZ endPoint2 = parallelLine2.GetEndPoint(0);
			XYZ endPoint3 = parallelLine2.GetEndPoint(1);
			XYZ xyz = Geometry.CalculateFootPoint(endPoint2, endPoint3, endPoint);
			bool flag = Geometry.IsEqual(xyz, endPoint2, DoubleCurveManager.m_dTolerance) || Geometry.IsEqual(xyz, endPoint3, DoubleCurveManager.m_dTolerance);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = Geometry.Is_Point_OnSegment(endPoint2, endPoint3, xyz, 1E-09);
				bool bFindAtLeft;
				if (flag2)
				{
					bFindAtLeft = Geometry.PointAtLineLeft(endPoint, endPoint2, endPoint3);
				}
				else
				{
					bFindAtLeft = !Geometry.PointAtLineLeft(endPoint, endPoint2, endPoint3);
				}
				Line linkLine = DoubleCurveManager.GetLinkLine(parallelLine1, nPointIndex, bFindAtLeft);
				Line linkLine2 = DoubleCurveManager.GetLinkLine(parallelLine2, nPointIndex, bFindAtLeft);
				bool flag3 = linkLine == null || linkLine2 == null;
				if (flag3)
				{
					result = false;
				}
				else
				{
					bool flag4 = !DoubleCurveManager.IsVectorParalel(linkLine.Direction, linkLine2.Direction);
					if (flag4)
					{
						result = false;
					}
					else
					{
						XYZ endPoint4 = linkLine.GetEndPoint(0);
						XYZ endPoint5 = linkLine.GetEndPoint(1);
						endPoint2 = linkLine2.GetEndPoint(0);
						endPoint3 = linkLine2.GetEndPoint(1);
						XYZ xyz2 = Geometry.CalculateFootPoint(endPoint4, endPoint5, endPoint2);
						XYZ ptE = Geometry.CalculateFootPoint(endPoint4, endPoint5, endPoint3);
						double val = xyz2.DistanceTo(endPoint2);
						bool flag5 = Geometry.GreaterThan(val, dMaxWidth) || Geometry.LessThan(val, dMinWidth);
						if (flag5)
						{
							result = false;
						}
						else
						{
							XYZ xyz3 = null;
							XYZ xyz4 = null;
							Geometry.OverlapType overlapType = Geometry.IsOverlapOfTwoLine(xyz2, ptE, endPoint4, endPoint5, ref xyz3, ref xyz4, true, 1E-09, 1E-09);
							bool flag6 = overlapType == Geometry.OverlapType._OT_None || overlapType == Geometry.OverlapType._OT_Linked;
							if (flag6)
							{
								result = false;
							}
							else
							{
								bool flag7 = xyz3 == null || xyz4 == null;
								result = !flag7;
							}
						}
					}
				}
			}
			return result;
		}

		private static Line GetLinkLine(Line CurrentLine, int nPointIndex, bool bFindAtLeft)
		{
			XYZ endPoint = CurrentLine.GetEndPoint(0);
			XYZ endPoint2 = CurrentLine.GetEndPoint(1);
			XYZ direction = CurrentLine.Direction;
			XYZ pt = (nPointIndex == 0) ? endPoint : endPoint2;
			for (int i = 0; i < DoubleCurveManager.m_lstAllCurve.Count; i++)
			{
				Line line = DoubleCurveManager.m_lstAllCurve[i] as Line;
				bool flag = line == null;
				if (!flag)
				{
					XYZ endPoint3 = line.GetEndPoint(0);
					XYZ endPoint4 = line.GetEndPoint(1);
					XYZ direction2 = line.Direction;
					bool flag2 = Geometry.IsEqual(endPoint, endPoint3) && Geometry.IsEqual(endPoint2, endPoint4);
					if (!flag2)
					{
						bool flag3 = DoubleCurveManager.IsVectorEqual(direction, direction2) || DoubleCurveManager.IsVectorReverse(direction, direction2);
						if (!flag3)
						{
							bool flag4 = Geometry.IsEqual(pt, endPoint3) && bFindAtLeft == Geometry.PointAtLineLeft(endPoint4, endPoint, endPoint2);
							Line result;
							if (flag4)
							{
								result = line;
							}
							else
							{
								bool flag5 = Geometry.IsEqual(pt, endPoint4) && bFindAtLeft == Geometry.PointAtLineLeft(endPoint3, endPoint, endPoint2);
								if (!flag5)
								{
									goto IL_FC;
								}
								result = line;
							}
							return result;
						}
					}
				}
				IL_FC:;
			}
			for (int j = 0; j < DoubleCurveManager.m_lstAllCurve.Count; j++)
			{
				Line line2 = DoubleCurveManager.m_lstAllCurve[j] as Line;
				bool flag6 = line2 == null;
				if (!flag6)
				{
					XYZ endPoint5 = line2.GetEndPoint(0);
					XYZ endPoint6 = line2.GetEndPoint(1);
					XYZ direction3 = line2.Direction;
					bool flag7 = Geometry.IsEqual(endPoint, endPoint5) && Geometry.IsEqual(endPoint2, endPoint6);
					if (!flag7)
					{
						bool flag8 = !DoubleCurveManager.IsVectorParalel(direction, direction3);
						if (!flag8)
						{
							bool flag9 = Geometry.IsEqual(pt, endPoint5) || Geometry.IsEqual(pt, endPoint6);
							if (flag9)
							{
								return line2;
							}
						}
					}
				}
			}
			return null;
		}

		private static void MergeGroupLines(List<Line> lstMainLine, List<Line> lstBeMergeLine)
		{
			for (int i = 0; i < lstMainLine.Count; i++)
			{
				Line line = lstMainLine[i];
				XYZ endPoint = line.GetEndPoint(0);
				XYZ endPoint2 = line.GetEndPoint(1);
				List<Line> list = new List<Line>();
				for (int j = 0; j < lstBeMergeLine.Count; j++)
				{
					Line line2 = lstBeMergeLine[j];
					bool flag = Geometry.GreaterThan(line2.Length, line.Length);
					if (!flag)
					{
						XYZ endPoint3 = line2.GetEndPoint(0);
						XYZ endPoint4 = line2.GetEndPoint(1);
						XYZ pt = Geometry.CalculateFootPoint(endPoint, endPoint2, endPoint3);
						XYZ pt2 = Geometry.CalculateFootPoint(endPoint, endPoint2, endPoint4);
						bool flag2 = Geometry.Is_Point_OnSegment(endPoint, endPoint2, pt, 1E-09) && Geometry.Is_Point_OnSegment(endPoint, endPoint2, pt2, 1E-09);
						if (flag2)
						{
							list.Add(line2);
						}
					}
				}
				bool flag3 = list.Count < 2;
				if (!flag3)
				{
					Line line3 = list[0];
					XYZ endPoint5 = line3.GetEndPoint(0);
					XYZ endPoint6 = line3.GetEndPoint(1);
					XYZ direction = line3.Direction;
					List<XYZ> list2 = new List<XYZ>();
					list2.Add(endPoint5);
					list2.Add(endPoint6);
					lstBeMergeLine.Remove(line3);
					for (int k = 1; k < list.Count; k++)
					{
						line3 = list[k];
						XYZ item = Geometry.CalculateFootPoint(endPoint5, endPoint6, line3.GetEndPoint(0));
						XYZ item2 = Geometry.CalculateFootPoint(endPoint5, endPoint6, line3.GetEndPoint(1));
						list2.Add(item);
						list2.Add(item2);
						lstBeMergeLine.Remove(line3);
					}
					DoubleCurveManager.SortPoints(list2, direction);
					Line item3 = Line.CreateBound(list2.First<XYZ>(), list2.Last<XYZ>());
					lstBeMergeLine.Add(item3);
				}
			}
		}

		private static void MergeGroupArcs(List<Arc> lstMainArc, List<Arc> lstBeMergeArc)
		{
			for (int i = 0; i < lstMainArc.Count; i++)
			{
				Arc arc = lstMainArc[i];
				XYZ endPoint = arc.GetEndPoint(0);
				XYZ endPoint2 = arc.GetEndPoint(1);
				List<Arc> list = new List<Arc>();
				for (int j = 0; j < lstBeMergeArc.Count; j++)
				{
					Arc arc2 = lstBeMergeArc[j];
					bool flag = Geometry.GreaterThan(arc2.Length, arc.Length);
					if (!flag)
					{
						XYZ endPoint3 = arc2.GetEndPoint(0);
						XYZ endPoint4 = arc2.GetEndPoint(1);
						XYZ pt = Geometry.CalculateFootPoint(endPoint, endPoint2, arc.Center, endPoint3);
						XYZ pt2 = Geometry.CalculateFootPoint(endPoint, endPoint2, arc.Center, endPoint4);
						bool flag2 = Geometry.Is_Point_OnSegment(endPoint, endPoint2, arc.Center, arc.Center, pt, 1E-09) && Geometry.Is_Point_OnSegment(endPoint, endPoint2, arc.Center, arc.Center, pt2, 1E-09);
						if (flag2)
						{
							list.Add(arc2);
						}
					}
				}
				bool flag3 = list.Count < 2;
				if (!flag3)
				{
					XYZ endPoint5 = list[0].GetEndPoint(0);
					XYZ endPoint6 = list[0].GetEndPoint(1);
					XYZ center = list[0].Center;
					XYZ normal = list[0].Normal;
					for (int k = 1; k < list.Count; k++)
					{
						Arc arc3 = list[k];
						XYZ ptExtend = Geometry.CalculateFootPoint(endPoint5, endPoint6, center, arc3.GetEndPoint(0));
						XYZ ptExtend2 = Geometry.CalculateFootPoint(endPoint5, endPoint6, center, arc3.GetEndPoint(1));
						DoubleCurveManager.ExtendArc(ptExtend, center, normal, ref endPoint5, ref endPoint6);
						DoubleCurveManager.ExtendArc(ptExtend2, center, normal, ref endPoint5, ref endPoint6);
						lstBeMergeArc.Remove(arc3);
					}
					XYZ xyz = Geometry.CalculatMidPoint(endPoint5, endPoint6, center, arc.Normal);
					Arc item = Arc.Create(endPoint5, endPoint6, xyz);
					lstBeMergeArc.Add(item);
				}
			}
		}

		private static void MergeOverlapLines(List<Line> lstLine)
		{
			bool flag = lstLine == null;
			if (!flag)
			{
				for (int i = 0; i < lstLine.Count - 1; i++)
				{
					Line line = lstLine[i];
					XYZ xyz = line.GetEndPoint(0);
					XYZ xyz2 = line.GetEndPoint(1);
					bool flag2 = false;
					for (int j = i + 1; j < lstLine.Count; j++)
					{
						Line line2 = lstLine[j];
						XYZ endPoint = line2.GetEndPoint(0);
						XYZ endPoint2 = line2.GetEndPoint(1);
						XYZ xyz3 = null;
						XYZ xyz4 = null;
						bool overlapLinePoint = DoubleCurveManager.GetOverlapLinePoint(xyz, xyz2, endPoint, endPoint2, ref xyz3, ref xyz4);
						if (overlapLinePoint)
						{
							lstLine.RemoveAt(j);
							xyz = xyz3;
							xyz2 = xyz4;
							flag2 = true;
							j = i;
						}
					}
					bool flag3 = flag2;
					if (flag3)
					{
						lstLine[i] = Line.CreateBound(xyz, xyz2);
					}
				}
			}
		}

		private static void MergeOverlapArcs(List<Arc> lstArc)
		{
			bool flag = lstArc == null;
			if (!flag)
			{
				for (int i = 0; i < lstArc.Count - 1; i++)
				{
					Arc arc = lstArc[i];
					XYZ xyz = arc.GetEndPoint(0);
					XYZ xyz2 = arc.GetEndPoint(1);
					XYZ center = arc.Center;
					XYZ normal = arc.Normal;
					bool flag2 = false;
					for (int j = i + 1; j < lstArc.Count; j++)
					{
						Arc arc2 = lstArc[j];
						XYZ endPoint = arc2.GetEndPoint(0);
						XYZ endPoint2 = arc2.GetEndPoint(1);
						XYZ center2 = arc2.Center;
						XYZ normal2 = arc2.Normal;
						XYZ xyz3 = null;
						XYZ xyz4 = null;
						Geometry.OverlapType overlapType = Geometry.MergerOfTwoArc(xyz, xyz2, center, normal, endPoint, endPoint2, center2, normal2, ref xyz3, ref xyz4, DoubleCurveManager.m_dTolerance);
						bool flag3 = overlapType != Geometry.OverlapType._OT_None && xyz3 != null && xyz4 != null;
						if (flag3)
						{
							lstArc.RemoveAt(j);
							j--;
							xyz = xyz3;
							xyz2 = xyz4;
							flag2 = true;
						}
					}
					bool flag4 = flag2;
					if (flag4)
					{
						XYZ xyz5 = Geometry.CalculatMidPoint(xyz, xyz2, center, normal);
						lstArc[i] = Arc.Create(xyz, xyz2, xyz5);
					}
				}
			}
		}

		private static bool GetOverlapLinePoint(XYZ ptS1, XYZ ptE1, XYZ ptS2, XYZ ptE2, ref XYZ ptMergeS, ref XYZ ptMergeE)
		{
			XYZ xyz = Geometry.CalculateFootPoint(ptS1, ptE1, ptS2);
			XYZ xyz2 = Geometry.CalculateFootPoint(ptS1, ptE1, ptE2);
			bool flag = Geometry.GreaterThan(ptS2.DistanceTo(xyz), DoubleCurveManager.m_dTolerance) || Geometry.GreaterThan(ptE2.DistanceTo(xyz2), DoubleCurveManager.m_dTolerance);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				List<XYZ> list = new List<XYZ>();
				list.Add(ptS1);
				list.Add(ptE1);
				list.Add(xyz);
				list.Add(xyz2);
				XYZ vtLine = (ptE1 - ptS1).Normalize();
				DoubleCurveManager.SortPoints(list, vtLine);
				XYZ xyz3 = list.First<XYZ>();
				XYZ xyz4 = list.Last<XYZ>();
				double val = ptS1.DistanceTo(ptE1) + ptS2.DistanceTo(ptE2);
				double val2 = xyz3.DistanceTo(xyz4);
				bool flag2 = Geometry.LessThan(val2, val, AssistFunc.mmToFeet(1.0));
				if (flag2)
				{
					ptMergeS = xyz3;
					ptMergeE = xyz4;
					result = true;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}

		private static void GetCurveGroups(List<Curve> lstCurve, Dictionary<XYZ, List<Line>> parallelLines, Dictionary<XYZ, List<Arc>> parallelArcs)
		{
			foreach (Curve curve in lstCurve)
			{
				bool flag = curve.Length < DoubleCurveManager.m_dTolerance;
				if (!flag)
				{
					bool flag2 = curve is Line;
					if (flag2)
					{
						Line line = curve as Line;
						XYZ direction = line.Direction;
						bool flag3 = parallelLines.ContainsKey(direction);
						if (flag3)
						{
							parallelLines[direction].Add(line);
						}
						else
						{
							bool flag4 = parallelLines.ContainsKey(-direction);
							if (flag4)
							{
								Line item = Line.CreateBound(line.GetEndPoint(1), line.GetEndPoint(0));
								parallelLines[-direction].Add(item);
							}
							else
							{
								parallelLines.Add(direction, new List<Line>
								{
									line
								});
							}
						}
					}
					else
					{
						bool flag5 = curve is Arc;
						if (flag5)
						{
							Arc arc = curve as Arc;
							bool flag6 = Geometry.IsEqual(arc.Normal, -XYZ.BasisZ, DoubleCurveManager.m_dTolerance);
							if (flag6)
							{
								XYZ endPoint = arc.GetEndPoint(1);
								XYZ endPoint2 = arc.GetEndPoint(0);
								XYZ xyz = arc.Evaluate(0.5, true);
								arc = Arc.Create(endPoint, endPoint2, xyz);
							}
							XYZ center = arc.Center;
							bool flag7 = parallelArcs.ContainsKey(center);
							if (flag7)
							{
								parallelArcs[center].Add(arc);
							}
							else
							{
								parallelArcs.Add(center, new List<Arc>
								{
									arc
								});
							}
						}
					}
				}
			}
		}

		private static bool IsVectorParalel(XYZ vt1, XYZ vt2)
		{
			return DoubleCurveManager.IsVectorEqual(vt1, vt2) || DoubleCurveManager.IsVectorReverse(vt1, vt2);
		}

		private static bool IsVectorEqual(XYZ vt1, XYZ vt2)
		{
			double val = vt1.AngleTo(vt2);
			return Geometry.LessThan(val, DoubleCurveManager.m_dTolerance);
		}

		private static bool IsVectorReverse(XYZ vt1, XYZ vt2)
		{
			double val = vt1.AngleTo(vt2);
			return Geometry.IsEqual(val, Math.PI, DoubleCurveManager.m_dTolerance);
		}

		private static bool IsVectorVertical(XYZ vt1, XYZ vt2)
		{
			double val = vt1.AngleTo(vt2);
			return Geometry.IsEqual(val, Math.PI*.5, DoubleCurveManager.m_dTolerance);
		}

		private static double GetConstWallWidth(double dWidth)
		{
			double dTol = 0.6;
			double dWidthMM = AssistFunc.feetToMM(dWidth);
			int num = DoubleCurveManager.ConstWallWidth.FirstOrDefault((int item) => Geometry.IsEqual(dWidthMM, (double)item, dTol));
			bool flag = num != 0;
			double result;
			if (flag)
			{
				result = AssistFunc.mmToFeet((double)num);
			}
			else
			{
				for (double num2 = 100.0; num2 < dWidthMM + 50.0; num2 += 50.0)
				{
					bool flag2 = Geometry.IsEqual(dWidthMM, num2, dTol);
					if (flag2)
					{
						return AssistFunc.mmToFeet(num2);
					}
				}
				result = -1.0;
			}
			return result;
		}

		private static bool GetParalelLineInfo(bool bIsWall, Line wallLine1, Line wallLine2, ref double thickness, ref Curve locationCurve)
		{
			XYZ endPoint = wallLine1.GetEndPoint(0);
			XYZ endPoint2 = wallLine1.GetEndPoint(1);
			XYZ endPoint3 = wallLine2.GetEndPoint(0);
			XYZ endPoint4 = wallLine2.GetEndPoint(1);
			XYZ xyz = Geometry.CalculateFootPoint(wallLine2, endPoint);
			XYZ ptE = Geometry.CalculateFootPoint(wallLine2, endPoint2);
			XYZ xyz2 = null;
			XYZ xyz3 = null;
			bool flag = !DoubleCurveManager.GetOverlapLinePoint(endPoint3, endPoint4, xyz, ptE, ref xyz2, ref xyz3);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XYZ xyz4 = (endPoint - xyz) / 2.0;
				XYZ xyz5 = xyz2 + xyz4;
				XYZ xyz6 = xyz3 + xyz4;
				thickness = endPoint.DistanceTo(xyz);
				locationCurve = Line.CreateBound(xyz5, xyz6);
				if (bIsWall)
				{
					thickness = DoubleCurveManager.GetConstWallWidth(thickness);
					bool flag2 = thickness < 0.0;
					if (flag2)
					{
						return false;
					}
				}
				result = true;
			}
			return result;
		}

		private static bool GetParalelArcInfo(Arc wallArc1, Arc wallArc2, ref double thickness, ref Curve locationCurve)
		{
			XYZ endPoint = wallArc1.GetEndPoint(0);
			XYZ endPoint2 = wallArc1.GetEndPoint(1);
			XYZ endPoint3 = wallArc2.GetEndPoint(0);
			XYZ endPoint4 = wallArc2.GetEndPoint(1);
			XYZ center = wallArc2.Center;
			XYZ ptS = center + (endPoint - center).Normalize() * wallArc2.Radius;
			XYZ ptE = center + (endPoint2 - center).Normalize() * wallArc2.Radius;
			XYZ xyz = null;
			XYZ xyz2 = null;
			Geometry.OverlapType overlapType = Geometry.MergerOfTwoArc(endPoint3, endPoint4, center, XYZ.BasisZ, ptS, ptE, center, XYZ.BasisZ, ref xyz, ref xyz2, 1E-09);
			bool flag = overlapType == Geometry.OverlapType._OT_None || xyz == null || xyz2 == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				double num = (wallArc1.Radius + wallArc2.Radius) / 2.0;
				XYZ xyz3 = center + (xyz - center).Normalize() * num;
				XYZ xyz4 = center + (xyz2 - center).Normalize() * num;
				thickness = Math.Abs(wallArc1.Radius - wallArc2.Radius);
				XYZ xyz5 = Geometry.CalculatMidPoint(xyz3, xyz4, center, XYZ.BasisZ);
				locationCurve = Arc.Create(xyz3, xyz4, xyz5);
				result = true;
			}
			return result;
		}

		private static void ExtendLine(XYZ ptExtend, ref XYZ ptLineS, ref XYZ ptLineE)
		{
			XYZ xyz = (ptLineE - ptLineS).Normalize();
			bool flag = !Geometry.Is_Point_OnSegment(ptLineS, ptLineE, ptExtend, DoubleCurveManager.m_dTolerance);
			if (flag)
			{
				XYZ xyz2 = (ptExtend - ptLineE).Normalize();
				bool flag2 = xyz2.IsAlmostEqualTo(xyz);
				if (flag2)
				{
					ptLineE = ptExtend;
				}
				else
				{
					ptLineS = ptExtend;
				}
			}
		}

		private static void ExtendArc(XYZ ptExtend, XYZ ptArcCenter, XYZ vtArcNormal, ref XYZ ptArcS, ref XYZ ptArcE)
		{
			bool flag = !Geometry.Is_Point_OnSegment(ptArcS, ptArcE, ptArcCenter, vtArcNormal, ptExtend, 1E-09);
			if (flag)
			{
				XYZ ptEnd = Geometry.CalculatMidPoint(ptArcS, ptArcE);
				bool flag2 = Geometry.PointAtLineLeft(ptArcS, ptArcCenter, ptEnd);
				bool flag3 = Geometry.PointAtLineLeft(ptExtend, ptArcCenter, ptEnd);
				bool flag4 = flag2 == flag3;
				if (flag4)
				{
					ptArcS = ptExtend;
				}
				else
				{
					ptArcE = ptExtend;
				}
			}
		}

		private static void SortPoints(List<XYZ> lstPt, XYZ vtLine)
		{
			for (int i = 0; i < lstPt.Count - 1; i++)
			{
				for (int j = i + 1; j < lstPt.Count; j++)
				{
					XYZ pt = (lstPt[j] - lstPt[i]).Normalize();
					bool flag = !Geometry.IsEqual(vtLine, pt);
					if (flag)
					{
						XYZ value = lstPt[i];
						lstPt[i] = lstPt[j];
						lstPt[j] = value;
					}
				}
			}
		}

		private static double m_dTolerance = ToleranceManger.GetToleranceManger().GetTolerance("墙线公差");

		private static List<Curve> m_lstAllCurve = new List<Curve>();

		private static int[] ConstWallWidth = new int[]
		{
			80,
			100,
			120,
			240,
			360,
			370
		};
	}
}
